package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    // 查询学员

    @GetMapping("/students")
    public Result selectStudent(StudentQueryParam studentQueryParam){
        PageBean studentList = studentService.selectStudent(studentQueryParam);
        return Result.success(studentList);
    }

   // 删除学员

    @DeleteMapping("/students/{ids}")
   public Result delStudentByIds(@PathVariable("ids") List<Integer> ids ){
        System.out.println("ids = " + ids);
        studentService.delStudentByIds(ids);

        return   Result.success();
   }

//    新增学生
    @PostMapping("/students")
    public Result insertStudent(@RequestBody Student student){

        studentService.insertStudent(student);
        return Result.success();
    }

//     根据id数据回显 /students/{id}

    @GetMapping("/students/{id}")
    public Result getStudentById(@PathVariable Integer id){
      Student student =  studentService.getStudentById(id);

        return Result.success(student);

    }
  //     修改内容 /students

    @PutMapping("/students")
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

//     违纪处理 /students/violation/{id}/{score}

    @PutMapping("/students/violation/{id}/{score}")
    public Result updateViolation(@PathVariable("id") Integer id,@PathVariable("score") Integer score){

        studentService.updateViolation(id,score);

      return Result.success();
    }

}
